package ferp.android.tasks.center;

import android.os.AsyncTask;
import ferp.android.managers.ProfileManager;
import ferp.center.client.Action;
import ferp.center.network.request.RequestProfileHacked;
import ferp.center.network.response.ResponseProfileHacked;
import ferp.core.log.Log;
import ferp.core.player.Profile;

/**
 * User: olegs
 * Date: 2/19/14 1:44 PM
 */
public class TaskProfileHacked extends AsyncTask<Profile, Void, Void>
{
  public static void report(ProfileManager pm)
  {
    for (Profile p : pm.getProfileList())
      if (p.useCenter && p.hacked && !p.reported)
        new TaskProfileHacked().execute(p);
  }

  @Override
  protected Void doInBackground(Profile... profiles)
  {
    try
    {
      RequestProfileHacked request = new RequestProfileHacked();

      request.id = profiles[0].centerId;

      profiles[0].reported = (Action.execute(Action.PROFILE_HACKED, request, ResponseProfileHacked.class) != null);
    }
    catch (Exception e)
    {
      Log.error(Action.TAG, e);
    }

    return null;
  }
}
